package tinybase.pf;

public class Statistic {
	
	public static final int STAT_BASE= 9000;
	public String psKey;
	public int iValue;
	StatisticsMgr statisticsMgr;
	
	public Statistic(StatisticsMgr statisticsMgr) {
		this.statisticsMgr= statisticsMgr;
	}
	
	public static final String PF_GETPAGE= "GETPAGE";
	public static final String PF_PAGEFOUND= "PAGEFOUND";
	public static final String PF_PAGENOTFOUND= "PAGENOTFOUND";
	public static final String PF_READPAGE= "READPAGE";
	public static final String PF_WRITEPAGE= "WRITEPAGE";
	public static final String PF_FLUSHPAGES= "FLUSHPAGES";
	
	
	public Statistic() {
		psKey= null;
		iValue= 0;
	}
	
	public Statistic(String psName) {
		this.psKey= new String(psName);
		iValue= 0;
	}
	
	public Statistic(Statistic stat) {
		this.psKey= new String(stat.psKey);
		this.iValue= stat.iValue;
	}
	
	public void statistics() {
		// First get all the statistics, must remember to delete memory returned
		int iGP= statisticsMgr.get(PF_GETPAGE);
		int iPF= statisticsMgr.get(PF_PAGEFOUND);
		int iPNF= statisticsMgr.get(PF_PAGENOTFOUND);
		int iRP= statisticsMgr.get(PF_READPAGE);
		int iWP= statisticsMgr.get(PF_WRITEPAGE);
		int iFP= statisticsMgr.get(PF_FLUSHPAGES);
		
		System.out.println("PF Layer Statistics");
		System.out.println("-------------------");
		
		System.out.print("Total number of calls to GetPage Routine: ");
		if (iGP != -1)
			System.out.println(iGP);
		else
			System.out.println("None");
		
		System.out.print(" Number found: ");
		if (iPF != -1)
			System.out.println(iPF);
		else
			System.out.println("None");
		
		System.out.print(" Number not found: ");
		if (iPNF != -1)
			System.out.println(iPNF);
		else
			System.out.println("None");
		System.out.println(" ------------------");
		
		System.out.print("Number of read requests: ");
		if (iRP != -1)
			System.out.println(iRP);
		else
			System.out.println("None");

		System.out.print("Numebr of write requests: ");
		if (iWP != -1)
			System.out.println(iWP);
		else
			System.out.println("None");
		System.out.println("---------------------");
		
		System.out.print("Number of flushes: ");
		if (iFP != -1)
			System.out.println(iFP);
		else
			System.out.println("None");
		System.out.println("----------------------");
	}
	
}
